package com.baiyang.sharding.utils;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @author 2024-06-13
 * @used letter构造器，当时success情况下data不能为空，考虑适配Android的网咯架构模式，针对被观察进行map方法转化从letter转化到t类型过程中，如果t==null，则报异常
 * @since 2024-06-13
 */
public class LetterUtils {
    private static DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
    /**
     * 异常
     */
    private static final String ERR = "error";
    /**
     * 成功
     **/
    private static final String SUC = "success";
    /**
     * 警告：数据不存在
     **/
    private static final String WAR = "warn";

    public static <T> Letter<T> success(T t) {
        return new Letter<T>(SUC, null, LocalDateTime.now().format(dateTimeFormatter), t);
    }

    public static <T> Letter<T> error(String msg) {
        return new Letter<T>(ERR, msg, LocalDateTime.now().format(dateTimeFormatter), null);
    }

    public static <T> Letter<T> warn(String msg) {
        return new Letter<>(WAR, msg, LocalDateTime.now().format(dateTimeFormatter), null);
    }
}
